let menuList = [
  {
    id: 0,
    name: "自动滚动",
    title: "自动滚动",
    active: false,
  },
  {
    id: 1,
    name: "标识表格",
    title: "查找页面表格（el-table和ivu-table）是否存在",
    active: false,
  },
  {
    id: 999,
    name: "test",
    title: "test",
    active: false,
  },
]

// sendMessageToPopupScript({ type: "update:menu", data: menuList })

// 监听从popup传来的消息
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
  switch (message.id) {
    case 0:
      if (message.active) {
        var autoScroll = new AutoScrollConstructor()
        menuList.some(v => {
          if(v.id===0){
            v.active=
          }
        })
      } else if (autoScroll !== undefined) {
        autoScroll.destory()
      }
      break

    case 110:

      break

    default:
      break
  }
  sendResponse()
})


if (/^https:\/\/mp\.weixin\.qq\.com/.test(window.location.href)) {
  console.log("开启自动滚动")
}

// autoScroll()

// 监听长连接
// chrome.runtime.onConnect.addListener(function (port) {
//   console.log(port);
//   if (port.name == 'test-connect') {
//     port.onMessage.addListener(function (msg) {
//       console.log('收到长连接消息：', msg);
//       if (msg.question == '你是谁啊？') port.postMessage({
//         answer: '我是你爸！'
//       });
//     });
//   }
// });

function sendMessageToPopupScript(message) {
  chrome.runtime.sendMessage(message, function (response) {
    console.log("收到来自popup的回复：" + response)
  })
}
